@extends('layouts.app')

{{--@section('content-header')
    <ul class="nav d-tabs clearfix">
        <li class="{{ empty($parent)? "active" : "" }}"><a href="{{ route('admin.category.index', ['parent' => 0]) }}"> 全部 </a></li>
        @foreach($topCategory as $value)
            <li class="{{ $parent == $value->id? "active" : "" }}"><a href="{{ route('admin.category.index', ['parent' => $value->id]) }}">{{ $value->name }}</a></li>
        @endforeach
        <li class="{{ $sidebar == "category"? "active" : "" }}"><a href="{{ route('admin.shop.category') }}">类别</a></li>
    </ul>
@endsection--}}
@section('content')
    <div class="content">
        <div class="row custom-invoice">
            <div class="row">
                <form method="get" action="{{ route('admin.category.index') }}">
                    <div class="form-group col-md-2 col-sm-6 col-xs-10" style="width:250px">
                        <input class="form-control" type="text" name="name" value="{{ $name }}" placeholder="分类名称">
                    </div>
                    <div class="form-group col-md-2 col-sm-10 col-xs-10" style="width:100px">
                        <button class="btn btn-success btn-ms" type="submit">搜索</button>
                    </div>
                </form>
            </div>
            @can('top_category-add')
                <a class="btn btn-success" href="{{ route("admin.category.create") }}">添加</a>
            @endcan
            <br />
            <br />
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <!-- <th>上级分类</th> -->
                    <th>分类名</th>
                    <th>前台显示</th>
                    <th>操作</th>
                    <th>排序权重</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $item)
                    <tr>
                        <!-- <td>{{ $item->parent }}</td> -->
                        <td>{{ $item->name }}</td>
                        <td>{!! $item->is_view_show ? "<i class='fa fa-check'></i>":"<i class='fa fa-close'></i>"  !!}</td>
                        <td>
                            @if (!in_array($item->name, $aIndexFixedCate))
                                @can("top_category-edit")
                                    <a class="btn btn-primary btn-xs" href="{{ route('admin.category.edit', ['category' => $item, ]) }}"><i class="fa fa-edit"></i>编辑</a>
                                @endcan
                                @can("top_category-delete")
                                        <a class="btn btn-danger btn-xs delete-confirm" data-href="{{ route('admin.category.destroy', ['category' => $item]) }}"><i class="fa fa-trash-o"></i> 删除</a>
                                @endcan
                            @endif
                        </td>
                        <td>
                            <input type="text" class="col-xs-3 change-sort" data-id="{{ $item->id }}" value="{{ $item->sort }}" />
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            {{ $data->links() }}
        </div>
    </div>
@endsection
@push('scripts')
    <script>
        $('.change-sort').on('change', function () {
            var sort = $(this).val();
            var id = $(this).attr('data-id');
            $.ajax({
                url: '{{ route('admin.category.sort') }}',
                type: "GET",
                dataType:'json',
                data: {
                    id: id,
                    sort: sort,
                },
                success: function (re) {
                }
            });
        });

    </script>
@endpush
